﻿#ifndef GAMECORE_THREAD_H
#define GAMECORE_THREAD_H

#include "GameLogical.h"

#include "../Game/GameDefine.h"
#include "../Game/SocketDefine.h"

#include "../_Global/GameModelThread.h"

class TcpSocket;
class GameCore_Thread : public GameModelThread
{
    Q_OBJECT
    //Q_ENUMS(_GameButtonValue);
    Q_PROPERTY(bool isWin READ isWin)   //是否获胜
    Q_PROPERTY(QObject* gameNormalLogical READ gameNormalLogical)
    Q_PROPERTY(QObject* gameFightLogical READ gameFightLogical)
    //Q_PROPERTY(QObjectList pokeList READ pokeList)


public:
    //构造函数：这里用来初始化一些固定数据（QML读取的固定数据）
    explicit GameCore_Thread(QObject *parent = nullptr);
    virtual ~GameCore_Thread();



//框架函数:

public:
    virtual int InitOnce() Q_DECL_OVERRIDE;   //进行初始化(仅1次，连同QML,由外部配置好后调用)
    virtual int InitOnceInThread() Q_DECL_OVERRIDE; //线程中初始化(1次)
    //初始化游戏
    virtual int GameInit(int sr = -1) Q_DECL_OVERRIDE;
    //游戏开始
    virtual GameClientModel::_GameStatus GameLoop();// Q_DECL_OVERRIDE;
    //游戏结束
    virtual int GameOver() Q_DECL_OVERRIDE;

    //根据游戏类型,进行初始化一些特定变量
    Q_INVOKABLE virtual void GameTypeInit();    //根据GameType初始化玩法

protected:
    //检测游戏是否结束,返回Game_Status_Continue或Game_Status_Gameover
    virtual GameModel::_GameStatus CheckGameOver() Q_DECL_OVERRIDE;



//框架(其他)

public:
    //void Sleep(unsigned long msec){msleep(msec);}

public slots:
    virtual void sl_UserActionFinished(){}

protected:
//UI游戏框架
    virtual void WaitForUserAction(){}


public slots:
//框架
    /*
    virtual void TerminateGame(GameClientModel::_GameStatus status = Game_Status_Exit, int ret = 0) Q_DECL_OVERRIDE
    {
        setGameStatus(status);
        qDebug() << "TerminateGame:" << ret;
    }
    */



//宠物游戏

//游戏属性
public:

    /*
    QObjectList pokeList() const
    {
        return m_PaiDuiList;
    }*/

    //Q_INVOKABLE QStringList strlist(){m_StrList.append("a");return m_StrList;}

    /*
    QObject* word()// const
    {
        return &wordObj;
    }*/

    virtual bool isWin() const
    {
        return true;
    }

    QObject* gameNormalLogical()
    {
        return &m_GameNormalLogical;
    }
    QObject* gameFightLogical()
    {
        return &m_GameFightLogical;
    }



//重载
protected:
    //virtual void run() Q_DECL_OVERRIDE;



//数据成员

public:
//游戏外部设置:
    int         m_nPlayerCount;     //玩家数
    int         m_nMyID;            //本人ID(下标)
    int         m_nGameMessageDelay;//游戏信息速度


//游戏数据
    GameNormalLogical   m_GameNormalLogical;
    GameFightLogical    m_GameFightLogical;

//游戏使用中数据
    QString     m_strMsg;

protected:
    //QML用
};

//Q_DECLARE_METATYPE(GameCore_Thread::_GameStatus)


#endif //GAMECORE_THREAD_H
